package com.lihan.controller;

import com.lihan.common.PageResponse;
import com.lihan.common.Result;
import com.lihan.model.dto.MomentFormDTO;
import com.lihan.model.vo.MomentVo;
import com.lihan.services.IMomentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Slf4j
@RestController
@RequestMapping("/moment")
@Api(tags = "朋友圈管理模块")
public class MomentController {

    @Resource
    private IMomentService momentService;

    @PostMapping("/publishMoment")
    @ApiOperation("发布朋友圈")
    public Result publicMoment(
            @ModelAttribute MomentFormDTO form // 自动绑定所有字段
    )  {

        if(form == null){
            return Result.errorMsg("请勿提交空表单");
        }
        Result result = momentService.saveMoment(form);
        return result;

    }

    @GetMapping("/getMoments")
    @ApiOperation("获取朋友圈记录")
    public PageResponse<MomentVo> getMoments(
            @RequestParam("userId") String userId,
            @RequestParam("page") Long page,
            @RequestParam("size") Long size
    ){
        PageResponse<MomentVo> result =  momentService.getMoments(userId,page,size);
        return result;
    }


}
